package cn.huanzi.qch.baseadmin.travel.thotel.service;

import cn.huanzi.qch.baseadmin.common.service.*;
import cn.huanzi.qch.baseadmin.travel.thotel.pojo.THotelPl;
import cn.huanzi.qch.baseadmin.travel.thotel.vo.THotelPlVo;
import cn.huanzi.qch.baseadmin.travel.thotel.repository.THotelPlRepository;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import java.util.ArrayList;
import java.util.List;

@Service
@Transactional
public class THotelPlServiceImpl extends CommonServiceImpl<THotelPlVo, THotelPl, Integer> implements THotelPlService {

    @PersistenceContext
    private EntityManager em;

    @Autowired
    private THotelPlRepository tHotelPlRepository;

    @Override
    public List<THotelPlVo> findPlByhotelId(Integer hotelId) {
        List<THotelPl> allByPlHotelId = tHotelPlRepository.findAllByPlHotelId(hotelId);
        ArrayList<THotelPlVo> tHotelPls = new ArrayList<>();
        THotelPlVo tHotelPlVo = new THotelPlVo();
        for (THotelPl tHotelPl : allByPlHotelId) {
            BeanUtils.copyProperties(tHotelPl, tHotelPlVo);
            tHotelPls.add(tHotelPlVo);
        }
        return tHotelPls;

    }

    @Override
    public List<THotelPlVo> all() {
        List<THotelPl> all = tHotelPlRepository.findAll();
        ArrayList<THotelPlVo> tHotelPlVos = new ArrayList<>();
        for (THotelPl tHotelPl : all) {
            THotelPlVo tHotelPlVo = new THotelPlVo();
            BeanUtils.copyProperties(tHotelPl, tHotelPlVo);
            tHotelPlVos.add(tHotelPlVo);
        }
        return tHotelPlVos;
    }
}
